# Contributor: Hoang Nguyen <folliekazetani@protonmail.com>
# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=stern
pkgver=1.27.0
pkgrel=0
pkgdesc="Multi pod and container log tailing for Kubernetes"
url="https://github.com/stern/stern"
arch="all"
license="Apache-2.0"
makedepends="go"
checkdepends="tzdata"
subpackages="
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/stern/stern/archive/refs/tags/v$pkgver.tar.gz"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	GOLDFLAGS="
	-X github.com/stern/stern/cmd.version=$pkgver
	-X github.com/stern/stern/cmd.commit=AlpineLinux
	-X github.com/stern/stern/cmd.date=$(date +%FT%T%Z)
	"
	go build -v -o bin/$pkgname -ldflags "$GOLDFLAGS"

	for shell in bash fish zsh; do
		./bin/stern --completion $shell > stern.$shell
	done
}

check() {
	go test ./...
}

package() {
	install -Dm755 bin/$pkgname -t "$pkgdir"/usr/bin/

	install -Dm644 stern.bash \
		"$pkgdir"/usr/share/bash-completion/completions/stern
	install -Dm644 stern.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_stern
	install -Dm644 stern.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/stern.fish
}

sha512sums="
71dd48d88d9ebb40e7c44c3a4d1aef54de6c58cb6f7d8535aacd8ad38bbf01e81574686377d904b22b6964c9394096e362671a5479c16ed6d55b7146ba988c51  stern-1.27.0.tar.gz
"
